<template>
  <div class="dashboard-editor-container">

    <panel-group @handleSetLineChartData="handleSetLineChartData" />

    <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
      <div>
        <span class="text-tab">收益对比</span>
        <line-chart :chart-data="lineChartData" />
      </div>
    </el-row>

    <el-row :gutter="32">
      <el-col :xs="24" :sm="24" :lg="8">
        <div class="chart-wrapper">
          <span class="text-tab">套餐统计</span>
          <empty-chart :cdata="Cdata" />
        </div>
      </el-col>
      <el-col :xs="24" :sm="24" :lg="8">
        <div class="chart-wrapper">
          <span class="text-tab">菜品统计</span>
          <pie-chart :ddata="Ddata"/>
        </div>
      </el-col>
      <el-col :xs="24" :sm="24" :lg="8">
        <div class="chart-wrapper">
          <div style="width: 15px;height: 9px; background-color: #ee6666;border-radius:3px;position: absolute;top: 35px"/>
          <span class="text-tab-contain" style="display: block;position: absolute;top: 31px;left: 50px">菜品Top1</span>
          <div style="width: 15px;height: 9px; background-color: #fac858;border-radius:3px;position: absolute;top: 50px"/>
          <span class="text-tab-contain" style="display: block;position: absolute;top: 46px;left: 50px">菜品Top2</span>
          <div style="width: 15px;height: 9px; background-color: #91cc75;border-radius:3px;position: absolute;top: 65px"/>
          <span class="text-tab-contain" style="display: block;position: absolute;top: 61px;left: 50px">菜品Top3</span>
          <div style="width: 15px;height: 9px; background-color: #5470c6;border-radius:3px;position: absolute;top: 35px;left: 120px"/>
          <span class="text-tab-contain" style="display: block;position: absolute;top: 31px;left: 154px">套餐Top1</span>
          <div style="width: 15px;height: 9px; background-color: #b6a2de;border-radius:3px;position: absolute;top: 50px;left: 120px"/>
          <span class="text-tab-contain" style="display: block;position: absolute;top: 46px;left: 154px">套餐Top2</span>
          <div style="width: 15px;height: 9px; background-color: #ffb980;border-radius:3px;position: absolute;top: 65px;left: 120px"/>
          <span class="text-tab-contain" style="display: block;position: absolute;top: 61px;left: 154px">套餐Top3</span>
          <span class="text-tab">菜品套餐TOP</span>
          <top-bar :tdata="Tdata" :xLabels="chartLabels"/>
        </div>
      </el-col>
    </el-row>


  </div>
</template>

<script>
import PanelGroup from './dashboard/PanelGroup'
import LineChart from './dashboard/LineChart'
import RaddarChart from './dashboard/RaddarChart'
import PieChart from './dashboard/PieChart'
import BarChart from './dashboard/BarChart'
import {getOtherCount, getTableCount} from "@/api/system/others";
import EmptyChart from "@/views/dashboard/emptyChart.vue";
import TopBar from "@/views/dashboard/topBar.vue";
import TopBarEnd from "@/views/dashboard/topBarEnd.vue";

let lineChartData = {
/*  newVisitis: {
    expectedData: [100, 120, 161, 134, 105, 160, 165],
    actualData: [120, 82, 91, 154, 162, 140, 145]
  },
  messages: {
    expectedData: [200, 192, 120, 144, 160, 130, 140],
    actualData: [180, 160, 151, 106, 145, 150, 130]
  },*/
  purchases: {
    expectedData: null,
    actualData: null
  },
  shoppings: {
    expectedData: null,
    actualData: null
  }
}

export default {
  name: 'Index',
  components: {
    TopBarEnd,
    TopBar,
    EmptyChart,
    PanelGroup,
    LineChart,
    RaddarChart,
    PieChart,
    BarChart
  },
  data() {
    return {
      keys: null,
      Ddata: [
        {value: 0,name: '肉菜'},
        {value: 0,name: '素菜'},
        {value: 0,name: '凉菜'},
        {value: 0,name: '主食饮品'},
      ],
      Cdata: [
        {value: 0,name: '单人餐'},
        {value: 0,name: '双人餐'},
        {value: 0,name: '三人餐'},
        {value: 0,name: '家庭餐'},
      ],
      Tdata:  [
        { value: null, color: '#ff0000' },
        { value: null, color: '#00ff00' },
        { value: null, color: '#0000ff' },
        { value: null, color: '#ff00ff' },
        { value: null, color: '#00ffff' },
        { value: null, color: '#ffff00' }
      ],
      chartLabels: [null, null, null, null, null, null],
      otherDates: null,
      otherData: null,
      lineChartData: lineChartData.purchases
    }
  },
  created() {
    this.getDatas();
    this.getDatasNow();
    this.getData();
    this.getDatassNow()
  },
  methods: {
    getDatas(){
      getTableCount().then(response => {
        this.otherData = response.data;
        lineChartData.purchases.expectedData=this.otherData.sevenBMoney;
        lineChartData.purchases.actualData=this.otherData.sevenMoney;
        lineChartData.shoppings.expectedData=this.otherData.sevenBOrders;
        lineChartData.shoppings.actualData=this.otherData.sevenOrders;
      })
    },
    getDatasNow(){
      setInterval(this.getDatas,3000);
    },
    handleSetLineChartData(type) {
      this.lineChartData = lineChartData[type]
    },
    getDatassNow(){
      setInterval(this.getData,3000);
    },
    // 父组件中
    getData() {
      getOtherCount(this.queryParams).then(response => {
        console.log(response.data); // 确保数据格式正确
        this.$set(this.Cdata, 0, { value: response.data.onlyCount, name: '单人餐' });
        this.$set(this.Cdata, 1, { value: response.data.doubleCount, name: '双人餐' });
        this.$set(this.Cdata, 2, { value: response.data.threeCount, name: '三人餐' });
        this.$set(this.Cdata, 3, { value: response.data.familyCount, name: '家庭餐' });
        this.$set(this.Ddata, 0, { value: response.data.mealCount, name: '肉菜' });
        this.$set(this.Ddata, 1, { value: response.data.plainCount, name: '素菜' });
        this.$set(this.Ddata, 2, { value: response.data.coldCount, name: '凉菜' });
        this.$set(this.Ddata, 3, { value: response.data.mainDrinkCount, name: '主食饮品' });
        this.keys = Object.entries(response.data.dishesAndComboTop);
        this.$set(this.Tdata, 0, { value: this.keys[0][1], color: '#ee6666' });
        this.$set(this.Tdata, 1, { value: this.keys[1][1], color: '#fac858' });
        this.$set(this.Tdata, 2, { value: this.keys[2][1], color: '#91cc75' });
        this.$set(this.Tdata, 3, { value: this.keys[3][1], color: '#5470c6' });
        this.$set(this.Tdata, 4, { value: this.keys[4][1], color: '#b6a2de' });
        this.$set(this.Tdata, 5, { value: this.keys[5][1], color: '#ffb980' });
        this.chartLabels[0] = this.keys[0][0];
        this.chartLabels[1] = this.keys[1][0];
        this.chartLabels[2] = this.keys[2][0];
        this.chartLabels[3] = this.keys[3][0];
        this.chartLabels[4] = this.keys[4][0];
        this.chartLabels[5] = this.keys[5][0];
      });
    }

  },
}
</script>

<style lang="scss" scoped>
.dashboard-editor-container {
  padding: 32px;
  background-color: rgb(240, 242, 245);
  position: relative;

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 32px;
    position: relative;
  }
}

@media (max-width:1024px) {
  .chart-wrapper {
    padding: 8px;
  }
}
.text-tab{
  font-weight: bold;
  text-align: center;
  display:block;
  line-height: 18px;
  color: rgba(0, 0, 0, 0.45);
  font-size: 16px;
}
.text-tab-contain{
  font-weight: lighter;
  text-align: center;
  display:block;
  line-height: 18px;
  font-size: 11px;
}
</style>
